package com.sgb.kjwl.view.ui.fragment.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppFragment;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentChildLeaseListBinding;
import com.sgb.kjwl.databinding.FragmentLeaseListBinding;
import com.sgb.kjwl.di.home.DaggerHomeFragComponent;
import com.sgb.kjwl.di.home.HomeFragModule;
import com.sgb.kjwl.model.entity.ShowCarEntity;
import com.sgb.kjwl.model.entity.ShowDeviceEntity;
import com.sgb.kjwl.model.entity.ShowFarmEntity;
import com.sgb.kjwl.model.entity.ShowMachineEntity;
import com.sgb.kjwl.model.entity.self.ShowFactoryEntity;
import com.sgb.kjwl.model.entity.self.ShowHouseEntity;
import com.sgb.kjwl.model.entity.self.ShowLandEntity;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.view.ui.activity.house.LeaseFactoryListFragment;
import com.sgb.kjwl.view.ui.activity.house.LeaseFarmListFragment;
import com.sgb.kjwl.view.ui.activity.house.LeaseHouseListFragment;
import com.sgb.kjwl.view.ui.activity.house.LeaseLandListFragment;
import com.sgb.kjwl.view.ui.adapter.home.ShowCarAdapter;
import com.sgb.kjwl.view.ui.adapter.home.ShowDeviceAdapter;
import com.sgb.kjwl.view.ui.adapter.home.ShowLeaseFactoryAdapter;
import com.sgb.kjwl.view.ui.adapter.home.ShowLeaseFarmAdapter;
import com.sgb.kjwl.view.ui.adapter.home.ShowLeaseHouseAdapter;
import com.sgb.kjwl.view.ui.adapter.home.ShowLeaseLandAdapter;
import com.sgb.kjwl.view.ui.adapter.home.ShowMechanicsAdapter;
import com.sgb.kjwl.view.ui.fragment.device.DeviceListFragment3;
import com.sgb.kjwl.view.ui.fragment.machine.CarListFragment3;
import com.sgb.kjwl.view.ui.fragment.machine.MachineListFragment3;
import com.sgb.kjwl.viewmodel.home.ChildLeaseListFragmentModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * 租赁首页推荐列表数据展示
 */
@Deprecated
public class ChildLeaseListFragment extends AppLazyFragment {

    @Inject
    ChildLeaseListFragmentModel model;
    FragmentChildLeaseListBinding binding;

    private FragPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments;
    private final String[] titles = {"全部", "机械租赁", "设备租赁", "车辆租赁", "房产租赁", "土地租赁", "工厂租赁", "农机租赁"};
    private int type = 0;

    public static ChildLeaseListFragment newInstance(int param) {
        ChildLeaseListFragment fragment = new ChildLeaseListFragment();
        Bundle args = new Bundle();
        args.putInt("type", param);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            type = getArguments().getInt("type");
        }
    }

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerHomeFragComponent.builder()
                .appComponent(appComponent)
                .homeFragModule(new HomeFragModule(this))
                .build()
                .inject(this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_child_lease_list, container, false);
        return binding.getRoot();
    }


    @Override
    protected void onLazyLoad() {
//        if (type != 0) {
//            binding.rvConditionSelection.setVisibility(View.VISIBLE);
//            model.getFilterTypeModel(String.valueOf(type));
//        } else {
//            binding.rvConditionSelection.setVisibility(View.GONE);
//        }
//        loadData();
    }

    @Override
    public void initView() {
        mFragments = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            if ("全部".equals(titles[i])) {
                mFragments.add(MachineListFragment3.newInstance());
            } else if ("机械租赁".equals(titles[i])) {
                mFragments.add(MachineListFragment3.newInstance());
            } else if ("设备租赁".equals(titles[i])) {
                mFragments.add(DeviceListFragment3.newInstance());
            } else if ("车辆租赁".equals(titles[i])) {
                mFragments.add(CarListFragment3.newInstance());
            } else if ("房产租赁".equals(titles[i])) {
                mFragments.add(LeaseHouseListFragment.newInstance());
            } else if ("土地租赁".equals(titles[i])) {
                mFragments.add(LeaseLandListFragment.newInstance());
            } else if ("工厂租赁".equals(titles[i])) {
                mFragments.add(LeaseFactoryListFragment.newInstance());
            } else if ("农机租赁".equals(titles[i])) {
                mFragments.add(LeaseFarmListFragment.newInstance());
            }
        }

        pagerAdapter = new FragPagerAdapter(getChildFragmentManager(), mFragments);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setOffscreenPageLimit(titles.length - 1);
        binding.tablayout.setViewPager(binding.viewpager, titles);
        binding.tablayout.setCurrentTab(0);
    }


}